package com.llt.pojo.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.llt.enum_util.ResponseBodyEnum;
//忽略字段·1
public class AjaxResponseBody {
    private int status;//状态码
    private String msg;//消息
    private Object data;//返回内容
    private String token;//加密
//    @JsonIgnore
    @JsonIgnore
    private ResponseBodyEnum bodyEnum;

    /**
     *
     * @param bodyEnum 枚举信息
     * @param data 返回的数据体
     * @param token token 可选参数
     */
    public AjaxResponseBody(ResponseBodyEnum bodyEnum,Object data,String token) {
        this.status = bodyEnum.getCode();
        this.msg = bodyEnum.getMsg();
        this.data = data;
        this.token = token;
    }
    public AjaxResponseBody(ResponseBodyEnum bodyEnum,Object data) {
        this.status = bodyEnum.getCode();
        this.msg = bodyEnum.getMsg();
        this.data = data;
    }
    public AjaxResponseBody(ResponseBodyEnum bodyEnum) {
        this.status = bodyEnum.getCode();
        this.msg = bodyEnum.getMsg();
    }
    public AjaxResponseBody() {
    }
    public static AjaxResponseBody fail(String msg) {

        AjaxResponseBody r = new AjaxResponseBody();
        r.setStatus(400);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }

    public static AjaxResponseBody fail(String msg, Object data) {
        AjaxResponseBody r = new AjaxResponseBody();
        r.setStatus(400);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static AjaxResponseBody fail(ResponseBodyEnum e ) {
        AjaxResponseBody r = new AjaxResponseBody();
        r.setStatus(e.getCode());
        r.setMsg(e.getMsg());
        return r;
    }
    public static AjaxResponseBody fail(int code, String msg, Object data) {
        AjaxResponseBody r = new AjaxResponseBody();
        r.setStatus(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public ResponseBodyEnum getBodyEnum() {
        return bodyEnum;
    }

    public void setBodyEnum(ResponseBodyEnum bodyEnum) {
       this.setStatus(bodyEnum.getCode());
       this.setMsg(bodyEnum.getMsg());
    }

    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public Object getData() {
        return data;
    }
    public void setData(Object data) {
        this.data = data;
    }
    public String getToken() {
        return token;
    }
    public void setToken(String token) {
        this.token = token;
    }
    @Override
    public String toString() {
        return "AjaxResponseBody{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", token='" + token + '\'' +
                '}';
    }
}
